const axios = require('axios');

async function testLogin() {
  try {
    console.log('尝试登录...');
    const response = await axios.post('http://localhost:3001/api/auth/login', {
      email: 'admin@example.com',
      password: '123456'
    });
    
    console.log('登录响应:', JSON.stringify(response.data, null, 2));
    
    if (response.data && response.data.data && response.data.data.token) {
      const token = response.data.data.token;
      console.log('Token获取成功:', token.substring(0, 20) + '...');
      
      // 测试分类API
      console.log('\n测试分类API...');
      const categoriesResponse = await axios.get('http://localhost:3001/api/menu/categories', {
        headers: {
          'Authorization': `Bearer ${token}`
        }
      });
      
      console.log('分类API响应:', JSON.stringify(categoriesResponse.data, null, 2));
    } else {
      console.log('登录失败，未获取到token');
    }
  } catch (error) {
    console.error('错误:', error.response?.data || error.message);
  }
}

testLogin();